//
//  ATImagerOperation.m
//  ATNetworks
//
//  Created by Ankit Thakur on 18/04/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ATImageOperation.h"


@implementation ATImageOperation

@synthesize callbackTarget;
@synthesize callbackSelector;
@synthesize identifier;
@synthesize imageURL;

+ (id) queueDataLoadWithURL:(NSURL*)anImageURL withIdentifier:(NSInteger)anIdentifier withCallbackTarget:(id)aTarget withCallbackSelector:(SEL)aSelector
{
	ATImageOperation *thisDataLoaderOperation = [[[ATImageOperation alloc] init] autorelease];
	
	thisDataLoaderOperation.callbackTarget = aTarget;
	thisDataLoaderOperation.callbackSelector = aSelector;
	thisDataLoaderOperation.identifier = anIdentifier;
	thisDataLoaderOperation.imageURL = anImageURL;
	
	return thisDataLoaderOperation;
}

- (void) main
{
	if ([callbackTarget respondsToSelector:callbackSelector]) {
		
		NSError *error = nil;
		NSData *data = [NSData dataWithContentsOfURL:imageURL
											 options:0
											   error:&error];

		NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:imageURL,@"imageUrl",data,@"imageData",nil];
		[callbackTarget performSelector:callbackSelector withObject:dict];
		data = nil;
	}
}

@end
